<?php
namespace app\common\model;

use think\Model;
use think\Db;
abstract class BaseSeller extends Model
{
    //缓存配置
    protected $cache_options =  [
        'type'=>'memcached',
        'host'=>'127.0.0.1',
        'port'=>'11211',
        'prefix'=>'water',
        'expire'=>60
    ];
    /**
     * 会员详细信息
     * @param array $condition
     * @param string $field
     * @return array
     */
    abstract public function getSellerInfo($condition, $field );

    /**
     * 会员列表
     * @param array $condition
     * @param string $field
     * @param number $page
     * @param string $order
     */
    abstract public function getSellerList($condition , $field , $order , $pagesize);

    /**
     * 会员数量
     * @param array $condition
     * @return int
     */
    public function getSellerCount($condition){
        return Db::name('shop_seller')->where($condition)->count();
    }

    /**
     * 登录时创建会话SESSION
     *
     * @param array $Seller_info 会员信息
     */
    public function createSession($seller_info = array()) {

    }

    /**
     * 注册
     */
    public function register($register_info) {

    }
    /**
     * 注册商城客服
     *
     * @param	array $param 会员信息
     * @return	array 数组格式的返回结果
     */
    public function addSeller($param) {
        if(empty($param)) {
            return false;
        }
        $seller_info = array(
            'seller_name'=>$param['seller_name'],
            'seller_company'=>$param['seller_company'],
            'seller_pass'=>$param['pass'],
            'seller_tel'=>$param['seller_tel'],
            'seller_avatar'=>$param['seller_avatar'],
            'seller_group_id'=>$param['seller_group_id'],
            'is_admin'=>$param['is_admin'],
            'seller_area'=>$param['seller_area'],
            'seller_address'=>$param['seller_address'],
            'seller_email'=>$param['seller_email'],
            'parent_id'=>$param['parent_id'],
            'last_login_time'=>time(),
            'status'=>1,
            'addtime'=>time()
        );
        if(isset($param['seller_truename'])&&!empty($param['seller_truename'])){
            $seller_info['seller_truename'] = trim($param['seller_truename']);
        }
        return Db::name('shop_seller')->insertGetId($seller_info);
    }

    /**
     * 更新会员信息
     *
     * @param	array $param 更改信息
     * @param	int $Seller_id 会员条件 id
     * @return	array 数组格式的返回结果
     */
    public function updateSeller($param,$seller_id) {
        if(empty($param)) {
            return false;
        }
        //得到条件语句
        $condition	= array(
            'seller_id'=> $seller_id
        );
        return Db::name('shop_seller')->where($condition)->update($param);
    }

    /**
     * 删除会员
     *
     * @param int $id 记录ID
     * @return array $rs_row 返回数组形式的查询结果
     */
    public function del($id){
        $id = intval($id);
        if ( $id > 0){
            $result = Db::name('shop_seller')->delete($id);
            return $result;
        }else {
            return false;
        }
    }
}